using System;
using EPiServer.Common;
using EPiServer.Common.Queries;
using EPiServer.Common.Security;
using EPiServer.Community.Blog;
using EPiServer.Community.Club;
using EPiServer.Community.Club.Queries;
using EPiServer.Community.Poll;

namespace EPiAbstractions.Community.Club
{
    public class ClubHandlerFacade : IClubHandlerFacade
    {
        private static ClubHandlerFacade _instance;

        public ClubHandlerFacade()
        {
            ClubHandler.ClubAdded += OnClubAdded;
            ClubHandler.ClubOpenAdded += OnClubOpenAdded;
            ClubHandler.ClubClosedAdded += OnClubClosedAdded;
            ClubHandler.ClubUpdated += OnClubUpdated;
            ClubHandler.ClubRemoved += OnClubRemoved;
            ClubHandler.AdAdded += OnAdAdded;
            ClubHandler.AdUpdated += OnAdUpdated;
            ClubHandler.AdRemoved += OnAdRemoved;
            ClubHandler.PollAdded += OnPollAdded;
            ClubHandler.PollRemoved += OnPollRemoved;
            ClubHandler.MembershipAdded += OnMembershipAdded;
            ClubHandler.MembershipUpdated += OnMembershipUpdated;
            ClubHandler.MembershipRemoved += OnMembershipRemoved;
        }

        public static ClubHandlerFacade Instance
        {
            get
            {
                if (_instance == null)
                    _instance = new ClubHandlerFacade();

                return _instance;
            }

            set { _instance = value; }
        }

        #region IClubHandlerFacade Members

        public event EPiServerCommonEventHandler ClubAdded;
        public event EPiServerCommonEventHandler ClubOpenAdded;
        public event EPiServerCommonEventHandler ClubClosedAdded;
        public event EPiServerCommonEventHandler ClubUpdated;
        public event EPiServerCommonEventHandler ClubRemoved;
        public event EPiServerCommonEventHandler AdAdded;
        public event EPiServerCommonEventHandler AdUpdated;
        public event EPiServerCommonEventHandler AdRemoved;
        public event EPiServerCommonEventHandler PollAdded;
        public event EPiServerCommonEventHandler PollRemoved;
        public event EPiServerCommonEventHandler MembershipAdded;
        public event EPiServerCommonEventHandler MembershipUpdated;
        public event EPiServerCommonEventHandler MembershipRemoved;

        public virtual EPiServer.Community.Club.Club AddClub(EPiServer.Community.Club.Club club)
        {
            return ClubHandler.AddClub(club);
        }

        public virtual void RemoveClub(EPiServer.Community.Club.Club club)
        {
            ClubHandler.RemoveClub(club);
        }

        public virtual void RemoveClub(EPiServer.Community.Club.Club club, Boolean permanent)
        {
            ClubHandler.RemoveClub(club, permanent);
        }

        public virtual void UpdateClub(EPiServer.Community.Club.Club club)
        {
            ClubHandler.UpdateClub(club);
        }

        public virtual EPiServer.Community.Club.Club GetClub(Int32 id)
        {
            return ClubHandler.GetClub(id);
        }

        public virtual ClubCollection GetClubs(String name)
        {
            return ClubHandler.GetClubs(name);
        }

        public virtual ClubCollection GetClubs(ClubApproval clubApproval, Int32 page, Int32 pageSize, ClubSortOrder[] sortOrder)
        {
            return ClubHandler.GetClubs(clubApproval, page, pageSize, sortOrder);
        }

        public virtual ClubCollection GetClubs(ClubApproval clubApproval, Int32 page, Int32 pageSize, out Int32 totalItems,
                                               ClubSortOrder[] sortOrder)
        {
            return ClubHandler.GetClubs(clubApproval, page, pageSize, out totalItems, sortOrder);
        }

        public virtual ClubCollection GetClubs(ClubApproval clubApproval, ClubHideStatus clubHideStatus, Int32 page, Int32 pageSize,
                                               ClubSortOrder[] sortOrder)
        {
            return ClubHandler.GetClubs(clubApproval, clubHideStatus, page, pageSize, sortOrder);
        }

        public virtual ClubCollection GetClubs(ClubApproval clubApproval, ClubHideStatus clubHideStatus, Int32 page, Int32 pageSize,
                                               out Int32 totalItems, ClubSortOrder[] sortOrder)
        {
            return ClubHandler.GetClubs(clubApproval, clubHideStatus, page, pageSize, out totalItems, sortOrder);
        }

        public virtual ClubCollection GetClubs(SiteCollection sites, ClubApproval clubApproval, ClubHideStatus clubHideStatus, Int32 page,
                                               Int32 pageSize, ClubSortOrder[] sortOrder)
        {
            return ClubHandler.GetClubs(sites, clubApproval, clubHideStatus, page, pageSize, sortOrder);
        }

        public virtual ClubCollection GetClubs(SiteCollection sites, ClubApproval clubApproval, ClubHideStatus clubHideStatus, Int32 page,
                                               Int32 pageSize, out Int32 totalItems, ClubSortOrder[] sortOrder)
        {
            return ClubHandler.GetClubs(sites, clubApproval, clubHideStatus, page, pageSize, out totalItems, sortOrder);
        }

        public virtual ClubCollection GetClubs(SiteCollection sites, NullValueAction siteNullAction, ClubApproval clubApproval,
                                               ClubHideStatus clubHideStatus, Int32 page, Int32 pageSize, ClubSortOrder[] sortOrder)
        {
            return ClubHandler.GetClubs(sites, siteNullAction, clubApproval, clubHideStatus, page, pageSize, sortOrder);
        }

        public virtual ClubCollection GetClubs(SiteCollection sites, NullValueAction siteNullAction, ClubApproval clubApproval,
                                               ClubHideStatus clubHideStatus, Int32 page, Int32 pageSize, out Int32 totalItems,
                                               ClubSortOrder[] sortOrder)
        {
            return ClubHandler.GetClubs(sites, siteNullAction, clubApproval, clubHideStatus, page, pageSize, out totalItems, sortOrder);
        }

        public virtual ClubCollection GetMyClubs(IUser user, Int32 page, Int32 pageSize, ClubSortOrder[] sortOrder)
        {
            return ClubHandler.GetMyClubs(user, page, pageSize, sortOrder);
        }

        public virtual ClubCollection GetMyClubs(IUser user, Int32 page, Int32 pageSize, out Int32 totalItems, ClubSortOrder[] sortOrder)
        {
            return ClubHandler.GetMyClubs(user, page, pageSize, out totalItems, sortOrder);
        }

        public virtual ClubCollection GetMyClubs(IUser user, ClubHideStatus clubHideStatus, Int32 page, Int32 pageSize,
                                                 ClubSortOrder[] sortOrder)
        {
            return ClubHandler.GetMyClubs(user, clubHideStatus, page, pageSize, sortOrder);
        }

        public virtual ClubCollection GetMyClubs(IUser user, ClubHideStatus clubHideStatus, Int32 page, Int32 pageSize, out Int32 totalItems,
                                                 ClubSortOrder[] sortOrder)
        {
            return ClubHandler.GetMyClubs(user, clubHideStatus, page, pageSize, out totalItems, sortOrder);
        }

        public virtual ClubCollection GetMyClubs(IUser user, SiteCollection sites, ClubHideStatus clubHideStatus, Int32 page, Int32 pageSize,
                                                 ClubSortOrder[] sortOrder)
        {
            return ClubHandler.GetMyClubs(user, sites, clubHideStatus, page, pageSize, sortOrder);
        }

        public virtual ClubCollection GetMyClubs(IUser user, SiteCollection sites, ClubHideStatus clubHideStatus, Int32 page, Int32 pageSize,
                                                 out Int32 totalItems, ClubSortOrder[] sortOrder)
        {
            return ClubHandler.GetMyClubs(user, sites, clubHideStatus, page, pageSize, out totalItems, sortOrder);
        }

        public virtual ClubCollection GetMyClubs(IUser user, SiteCollection sites, NullValueAction siteNullAction,
                                                 ClubHideStatus clubHideStatus, Int32 page, Int32 pageSize, ClubSortOrder[] sortOrder)
        {
            return ClubHandler.GetMyClubs(user, sites, siteNullAction, clubHideStatus, page, pageSize, sortOrder);
        }

        public virtual ClubCollection GetMyClubs(IUser user, SiteCollection sites, NullValueAction siteNullAction,
                                                 ClubHideStatus clubHideStatus, Int32 page, Int32 pageSize, out Int32 totalItems,
                                                 ClubSortOrder[] sortOrder)
        {
            return ClubHandler.GetMyClubs(user, sites, siteNullAction, clubHideStatus, page, pageSize, out totalItems, sortOrder);
        }

        public virtual ClubCollection GetRelatedClubs(EPiServer.Community.Club.Club club, Int32 minRelatedMembers,
                                                      Int32 minRelatedMemberPercentage, Int32 page, Int32 pageSize,
                                                      ClubSortOrder[] sortOrder)
        {
            return ClubHandler.GetRelatedClubs(club, minRelatedMembers, minRelatedMemberPercentage, page, pageSize, sortOrder);
        }

        public virtual ClubCollection GetRelatedClubs(EPiServer.Community.Club.Club club, Int32 minRelatedMembers,
                                                      Int32 minRelatedMemberPercentage, Int32 page, Int32 pageSize, out Int32 totalItems,
                                                      ClubSortOrder[] sortOrder)
        {
            return ClubHandler.GetRelatedClubs(club, minRelatedMembers, minRelatedMemberPercentage, page, pageSize, out totalItems,
                                               sortOrder);
        }

        public virtual ClubCollection GetRelatedClubs(EPiServer.Community.Club.Club club, Int32 minRelatedMembers,
                                                      Int32 minRelatedMemberPercentage, ClubHideStatus clubHideStatus, Int32 page,
                                                      Int32 pageSize, ClubSortOrder[] sortOrder)
        {
            return ClubHandler.GetRelatedClubs(club, minRelatedMembers, minRelatedMemberPercentage, clubHideStatus, page, pageSize,
                                               sortOrder);
        }

        public virtual ClubCollection GetRelatedClubs(EPiServer.Community.Club.Club club, Int32 minRelatedMembers,
                                                      Int32 minRelatedMemberPercentage, ClubHideStatus clubHideStatus, Int32 page,
                                                      Int32 pageSize, out Int32 totalItems, ClubSortOrder[] sortOrder)
        {
            return ClubHandler.GetRelatedClubs(club, minRelatedMembers, minRelatedMemberPercentage, clubHideStatus, page, pageSize,
                                               out totalItems, sortOrder);
        }

        public virtual ClubCollection GetRelatedClubs(EPiServer.Community.Club.Club club, SiteCollection sites, Int32 minRelatedMembers,
                                                      Int32 minRelatedMemberPercentage, ClubHideStatus clubHideStatus, Int32 page,
                                                      Int32 pageSize, ClubSortOrder[] sortOrder)
        {
            return ClubHandler.GetRelatedClubs(club, sites, minRelatedMembers, minRelatedMemberPercentage, clubHideStatus, page, pageSize,
                                               sortOrder);
        }

        public virtual ClubCollection GetRelatedClubs(EPiServer.Community.Club.Club club, SiteCollection sites, Int32 minRelatedMembers,
                                                      Int32 minRelatedMemberPercentage, ClubHideStatus clubHideStatus, Int32 page,
                                                      Int32 pageSize, out Int32 totalItems, ClubSortOrder[] sortOrder)
        {
            return ClubHandler.GetRelatedClubs(club, sites, minRelatedMembers, minRelatedMemberPercentage, clubHideStatus, page, pageSize,
                                               out totalItems, sortOrder);
        }

        public virtual ClubCollection GetRelatedClubs(EPiServer.Community.Club.Club club, SiteCollection sites,
                                                      NullValueAction siteNullAction, Int32 minRelatedMembers,
                                                      Int32 minRelatedMemberPercentage, ClubHideStatus clubHideStatus, Int32 page,
                                                      Int32 pageSize, ClubSortOrder[] sortOrder)
        {
            return ClubHandler.GetRelatedClubs(club, sites, siteNullAction, minRelatedMembers, minRelatedMemberPercentage, clubHideStatus,
                                               page, pageSize, sortOrder);
        }

        public virtual ClubCollection GetRelatedClubs(EPiServer.Community.Club.Club club, SiteCollection sites,
                                                      NullValueAction siteNullAction, Int32 minRelatedMembers,
                                                      Int32 minRelatedMemberPercentage, ClubHideStatus clubHideStatus, Int32 page,
                                                      Int32 pageSize, out Int32 totalItems, ClubSortOrder[] sortOrder)
        {
            return ClubHandler.GetRelatedClubs(club, sites, siteNullAction, minRelatedMembers, minRelatedMemberPercentage, clubHideStatus,
                                               page, pageSize, out totalItems, sortOrder);
        }

        public virtual Membership AddMembership(Membership cm)
        {
            return ClubHandler.AddMembership(cm);
        }

        public virtual void UpdateMembership(Membership cm)
        {
            ClubHandler.UpdateMembership(cm);
        }

        public virtual void RemoveMembership(Membership cm)
        {
            ClubHandler.RemoveMembership(cm);
        }

        public virtual MembershipCollection GetMembers(EPiServer.Community.Club.Club club, Int32 page, Int32 pageSize,
                                                       MembershipSortOrder[] sortOrder)
        {
            return ClubHandler.GetMembers(club, page, pageSize, sortOrder);
        }

        public virtual MembershipCollection GetMembers(EPiServer.Community.Club.Club club, Int32 page, Int32 pageSize, out Int32 totalItems,
                                                       MembershipSortOrder[] sortOrder)
        {
            return ClubHandler.GetMembers(club, page, pageSize, out totalItems, sortOrder);
        }

        public virtual MembershipCollection GetMembers(EPiServer.Community.Club.Club club, MembershipApproval approval, Int32 page,
                                                       Int32 pageSize, MembershipSortOrder[] sortOrder)
        {
            return ClubHandler.GetMembers(club, approval, page, pageSize, sortOrder);
        }

        public virtual MembershipCollection GetMembers(EPiServer.Community.Club.Club club, MembershipApproval approval, Int32 page,
                                                       Int32 pageSize, out Int32 totalItems, MembershipSortOrder[] sortOrder)
        {
            return ClubHandler.GetMembers(club, approval, page, pageSize, out totalItems, sortOrder);
        }

        public virtual Membership GetMembership(Int32 id)
        {
            return ClubHandler.GetMembership(id);
        }

        public virtual Membership GetMembership(EPiServer.Community.Club.Club club, IUser user)
        {
            return ClubHandler.GetMembership(club, user);
        }

        public virtual PollCollection GetClubPolls(EPiServer.Community.Club.Club club, Int32 page, Int32 pageSize, PollSortOrder[] order)
        {
            return ClubHandler.GetClubPolls(club, page, pageSize, order);
        }

        public virtual PollCollection GetClubPolls(EPiServer.Community.Club.Club club, Int32 page, Int32 pageSize, out Int32 totalItems,
                                                   PollSortOrder[] order)
        {
            return ClubHandler.GetClubPolls(club, page, pageSize, out totalItems, order);
        }

        public virtual Poll AddClubPoll(EPiServer.Community.Club.Club club, Poll poll)
        {
            return ClubHandler.AddClubPoll(club, poll);
        }

        public virtual void RemoveClubPoll(EPiServer.Community.Club.Club club, Poll poll)
        {
            ClubHandler.RemoveClubPoll(club, poll);
        }

        public virtual Ad AddAd(Ad ad)
        {
            return ClubHandler.AddAd(ad);
        }

        public virtual void UpdateAd(Ad ad)
        {
            ClubHandler.UpdateAd(ad);
        }

        public virtual void RemoveAd(Ad ad)
        {
            ClubHandler.RemoveAd(ad);
        }

        public virtual Ad GetAd(Int32 id)
        {
            return ClubHandler.GetAd(id);
        }

        public virtual AdCollection GetAds(AdApproval adApproval, Int32 page, Int32 pageSize, AdSortOrder[] sortOrder)
        {
            return ClubHandler.GetAds(adApproval, page, pageSize, sortOrder);
        }

        public virtual AdCollection GetAds(AdApproval adApproval, Int32 page, Int32 pageSize, out Int32 totalItems, AdSortOrder[] sortOrder)
        {
            return ClubHandler.GetAds(adApproval, page, pageSize, out totalItems, sortOrder);
        }

        public virtual AdCollection GetAds(SiteCollection sites, AdApproval adApproval, Int32 page, Int32 pageSize, AdSortOrder[] sortOrder)
        {
            return ClubHandler.GetAds(sites, adApproval, page, pageSize, sortOrder);
        }

        public virtual AdCollection GetAds(SiteCollection sites, AdApproval adApproval, Int32 page, Int32 pageSize, out Int32 totalItems,
                                           AdSortOrder[] sortOrder)
        {
            return ClubHandler.GetAds(sites, adApproval, page, pageSize, out totalItems, sortOrder);
        }

        public virtual AdCollection GetAds(EPiServer.Community.Club.Club club, AdApproval adApproval, Int32 page, Int32 pageSize,
                                           AdSortOrder[] sortOrder)
        {
            return ClubHandler.GetAds(club, adApproval, page, pageSize, sortOrder);
        }

        public virtual AdCollection GetAds(EPiServer.Community.Club.Club club, AdApproval adApproval, Int32 page, Int32 pageSize,
                                           out Int32 totalItems, AdSortOrder[] sortOrder)
        {
            return ClubHandler.GetAds(club, adApproval, page, pageSize, out totalItems, sortOrder);
        }

        public virtual AdCollection GetAds(EPiServer.Community.Club.Club club, SiteCollection sites, AdApproval adApproval, Int32 page,
                                           Int32 pageSize, AdSortOrder[] sortOrder)
        {
            return ClubHandler.GetAds(club, sites, adApproval, page, pageSize, sortOrder);
        }

        public virtual AdCollection GetAds(EPiServer.Community.Club.Club club, SiteCollection sites, AdApproval adApproval, Int32 page,
                                           Int32 pageSize, out Int32 totalItems, AdSortOrder[] sortOrder)
        {
            return ClubHandler.GetAds(club, sites, adApproval, page, pageSize, out totalItems, sortOrder);
        }

        public virtual AdCollection GetAds(EPiServer.Community.Club.Club club, SiteCollection sites, NullValueAction siteNullAction,
                                           AdApproval adApproval, Int32 page, Int32 pageSize, AdSortOrder[] sortOrder)
        {
            return ClubHandler.GetAds(club, sites, siteNullAction, adApproval, page, pageSize, sortOrder);
        }

        public virtual AdCollection GetAds(EPiServer.Community.Club.Club club, SiteCollection sites, NullValueAction siteNullAction,
                                           AdApproval adApproval, Int32 page, Int32 pageSize, out Int32 totalItems, AdSortOrder[] sortOrder)
        {
            return ClubHandler.GetAds(club, sites, siteNullAction, adApproval, page, pageSize, out totalItems, sortOrder);
        }

        public virtual EntryCollection GetClubEntries(IUser user, ClubBlogType clubBlogType, ReadStatus readStatus, Int32 page,
                                                      Int32 pageSize, EntrySortOrder[] sortOrder)
        {
            return ClubHandler.GetClubEntries(user, clubBlogType, readStatus, page, pageSize, sortOrder);
        }

        public virtual EntryCollection GetClubEntries(IUser user, ClubBlogType clubBlogType, ReadStatus readStatus, Int32 page,
                                                      Int32 pageSize, out Int32 totalItems, EntrySortOrder[] sortOrder)
        {
            return ClubHandler.GetClubEntries(user, clubBlogType, readStatus, page, pageSize, out totalItems, sortOrder);
        }

        public virtual Int32 GetNumClubEntries(IUser user, ClubBlogType clubBlogType, ReadStatus readStatus)
        {
            return ClubHandler.GetNumClubEntries(user, clubBlogType, readStatus);
        }

        public virtual AdCollection GetQueryResult(AdQuery query)
        {
            return ClubHandler.GetQueryResult(query);
        }

        public virtual AdCollection GetQueryResult(AdQuery query, Int32 page, Int32 pageSize)
        {
            return ClubHandler.GetQueryResult(query, page, pageSize);
        }

        public virtual AdCollection GetQueryResult(AdQuery query, Int32 page, Int32 pageSize, out Int32 totalItems)
        {
            return ClubHandler.GetQueryResult(query, page, pageSize, out totalItems);
        }

        public virtual ClubCollection GetQueryResult(ClubQuery query)
        {
            return ClubHandler.GetQueryResult(query);
        }

        public virtual ClubCollection GetQueryResult(ClubQuery query, Int32 page, Int32 pageSize)
        {
            return ClubHandler.GetQueryResult(query, page, pageSize);
        }

        public virtual ClubCollection GetQueryResult(ClubQuery query, Int32 page, Int32 pageSize, out Int32 totalItems)
        {
            return ClubHandler.GetQueryResult(query, page, pageSize, out totalItems);
        }

        public virtual MembershipCollection GetQueryResult(MembershipQuery query)
        {
            return ClubHandler.GetQueryResult(query);
        }

        public virtual MembershipCollection GetQueryResult(MembershipQuery query, Int32 page, Int32 pageSize)
        {
            return ClubHandler.GetQueryResult(query, page, pageSize);
        }

        public virtual MembershipCollection GetQueryResult(MembershipQuery query, Int32 page, Int32 pageSize, out Int32 totalItems)
        {
            return ClubHandler.GetQueryResult(query, page, pageSize, out totalItems);
        }

        #endregion

        public virtual void OnClubAdded(String sender, EPiServerCommonEventArgs e)
        {
            if (ClubAdded != null)
                ClubAdded(sender, e);
        }

        public virtual void OnClubOpenAdded(String sender, EPiServerCommonEventArgs e)
        {
            if (ClubOpenAdded != null)
                ClubOpenAdded(sender, e);
        }

        public virtual void OnClubClosedAdded(String sender, EPiServerCommonEventArgs e)
        {
            if (ClubClosedAdded != null)
                ClubClosedAdded(sender, e);
        }

        public virtual void OnClubUpdated(String sender, EPiServerCommonEventArgs e)
        {
            if (ClubUpdated != null)
                ClubUpdated(sender, e);
        }

        public virtual void OnClubRemoved(String sender, EPiServerCommonEventArgs e)
        {
            if (ClubRemoved != null)
                ClubRemoved(sender, e);
        }

        public virtual void OnAdAdded(String sender, EPiServerCommonEventArgs e)
        {
            if (AdAdded != null)
                AdAdded(sender, e);
        }

        public virtual void OnAdUpdated(String sender, EPiServerCommonEventArgs e)
        {
            if (AdUpdated != null)
                AdUpdated(sender, e);
        }

        public virtual void OnAdRemoved(String sender, EPiServerCommonEventArgs e)
        {
            if (AdRemoved != null)
                AdRemoved(sender, e);
        }

        public virtual void OnPollAdded(String sender, EPiServerCommonEventArgs e)
        {
            if (PollAdded != null)
                PollAdded(sender, e);
        }

        public virtual void OnPollRemoved(String sender, EPiServerCommonEventArgs e)
        {
            if (PollRemoved != null)
                PollRemoved(sender, e);
        }

        public virtual void OnMembershipAdded(String sender, EPiServerCommonEventArgs e)
        {
            if (MembershipAdded != null)
                MembershipAdded(sender, e);
        }

        public virtual void OnMembershipUpdated(String sender, EPiServerCommonEventArgs e)
        {
            if (MembershipUpdated != null)
                MembershipUpdated(sender, e);
        }

        public virtual void OnMembershipRemoved(String sender, EPiServerCommonEventArgs e)
        {
            if (MembershipRemoved != null)
                MembershipRemoved(sender, e);
        }
    }
}